package com.commods.main.view.components.historicalChart.proto.temp
{
	import flash.display.DisplayObject;
	import flash.geom.Point;
	import mx.charts.AxisRenderer;
	import mx.charts.DateTimeAxis;
	import mx.charts.HLOCChart;
	import mx.charts.series.HLOCSeries;
	import mx.charts.series.LineSeries;
	import mx.collections.ArrayCollection;
	import mx.controls.Label;
	import mx.formatters.DateFormatter;
	import mx.states.OverrideBase;
	import mx.utils.StringUtil;
	
	public class HlocAxisRenderer extends AxisRenderer
	{
		public function HlocAxisRenderer()
		{
			super();
		}
		
		private static const WEEKS:Number = 4;
		private var _lines:ArrayCollection = new ArrayCollection();
		override protected function createChildren():void{
			super.createChildren();
			for(var i:uint=0; i<WEEKS; i++){
				var curLine:VDashRule =  new VDashRule()
				_lines.addItem(curLine);
				addChild(curLine);
			}
		
		
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
			var daxis:DateTimeAxis = (this.chart as HLOCChart).horizontalAxis as DateTimeAxis;
			var curDate:Date = daxis.maximum;

			var targetSeri:HLOCSeries = ((this.chart as HLOCChart).series[0] as HLOCSeries);
			var count:Number = _lines.length;
			while(count>0){
				var isLineDay:Boolean = (curDate.day==0); //weekend
				if(!isLineDay){
					curDate = TempUtils.dateAdd("date", -1, curDate);
					continue;
				}

				var index:uint = count-1;
				var curLine:VDashRule = _lines.getItemAt(index) as VDashRule;
				curLine.bottomLabelText = StringUtil.substitute("-{0}w", _lines.length-count+1);
				var pt:Point = targetSeri.dataToLocal(curDate);
				curLine.height = unscaledHeight;
				curLine.move(pt.x, pt.y);
		
				count--;
				curDate = TempUtils.dateAdd("date", -1, curDate);
			}

			
		}
	}
}